package com.example.floatingactionbuttondemo.utils;

import android.content.Context;

/**
 * 屏幕工具类
 *
 * @author wdl
 */
public class UiUtils {

    public static int dp2px(Context context, float dpValue) {
        //获取屏幕的密度：density = densityDpi/160
        float scale = context.getResources().getDisplayMetrics().density;
        // + 0.5f是为了四舍五入转换成int类型
        return (int) (dpValue * scale + 0.5f);
    }

    public static int px2dp(Context context, float pxValue) {
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }
}
